// var tcity = require("../../../utils/citys.js");
var app = getApp();
var flag=false;
Page({
  data:{
    array: ['天桥区', '历下区', '历城区', '槐荫区', '市中区', '高新区'],
    nameholder:"请填写您的姓名",
    phoneholder:"请填写您的联系方式",
    nowCity:"请填写您所在城市",
    nowDistrict:"请填写您所在城区",
    city:"济南市",
    focus:"",
    detail:"",
    area:"",
    name:"",
    phone:"",
    detailholder:"街道门牌信息",
  },
  bindPickerChange: function (e) {
    var array = this.data.array
    var index1 = e.detail.value
    this.setData({
      index: e.detail.value,
      area: array[index1]
    })
  },
  onLoad: function (options) {
    var modifyaddress = wx.getStorageSync('modifyaddress')
    this.setData({
      name: modifyaddress.name,
      phone: modifyaddress.phone,
      city: modifyaddress.city,
      area: modifyaddress.area,
      detail: modifyaddress.detail,
      id: modifyaddress.id,
      isDefault: modifyaddress.isDefault,
    })
  },
  
  //点击删除
  deleteIt:function(){
    var modify = this.data.id
      wx.showModal({
       title: '提示',
       content: '确认删除该地址信息吗？',
       success: function(res) {
         if (res.confirm) {
           wx.setStorageSync('modify', modify)        
            wx.redirectTo({
              url: '../selectAddress/index'
             }); 
          } else if (res.cancel) {
           console.log('用户点击取消')
            }
          } 
      })
},
//点击取消，返回上个页面
  cancel:function(){
    wx.redirectTo({
     url: '../selectAddress/index'
    })
 },
    //点击保存
  formSubmit: function(e) {
    var warn ="";
    var that = this;
    if(e.detail.value.name==""){
      warn = "请填写您的姓名！";
    } else if (e.detail.value.phone==""){
      warn = "请填写您的手机号！";
    } else if (!(/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value.phone))){
      warn = "手机号格式不正确";
    } else if(e.detail.value.city==''){
      warn = "请选择您的所在城市";
    } else if (e.detail.value.addre ==''){
      warn = "请选择您的所在城区";
    } else if (e.detail.value.detail==""){
      warn = "请输入您的具体地址";
    }else{
      flag=true;
      console.log('form发生了submit事件，携带数据为：', e.detail.value)
      var newmodifyaddress = e.detail.value
      newmodifyaddress.id = that.data.id
      newmodifyaddress.isDefault = that.data.isDefault
      wx.setStorageSync('newmodifyaddress', newmodifyaddress)
        wx.redirectTo({
          url: '../selectAddress/index'
      }); 
    }
    if(flag==false){
      wx.showModal({
      title: '提示',
      content:warn
    })
    } 
  }, 
  })